<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("conn.php");
$db = new DBC();

if (isset($_GET['id'])) {
    $sql = "SELECT * FROM t_search_info WHERE id = " . $_GET['id'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $id = $data[0]['id'];
        $position = $data[0]['position'];
        $imageURL = $data[0]['imageURL'];
        $status = $data[0]['status'];
        $click = $data[0]['click'];
        $isModify = 1;
    }
} else {
    $position = "";
    $imageURL = "";
    $status = 0;
    $click = 0;
    $isModify = 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }

            .text{
                height:20px;
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style>
        <script language="javascript">
            function onchange_age(){
                var obj = document.getElementById("age");
                var age = obj.options[obj.selectedIndex].value;

            }

            function onSubmitCheck(){
                var flashcode = document.getElementById("flashcode").value;
                var flashname = document.getElementById("flashname").value;
                var type2 = document.getElementsByName("type2[]");
                var version = document.getElementById("version").value;
                var apkurl = document.getElementById("apkurl").value;
                var isok = true;
                var ischecked = false;
                for(var i=0;i<type2.length;i++){
                    if(type2[i].checked==true){
                        ischecked = true;
                        break;
                    }
                }
                if(flashcode==""){
                    alert("\u8bf7输入编码");
                    isok = false;
                }else if(flashname==""){
                    al\u8bf7rt("\u8bf7输入名称");
                    isok = false;
                }else if(version==""){
                    al\u8bf7rt("\u8bf7输入版本");
                    isok = false;
                }else if(apkurl==""){
                    al\u8bf7rt("\u8bf7输入应用地址");
                    isok = false;
                }else if(!ischecked){
                    alert("\u8bf7至少选择一项能力");
                    isok = false;
                }
                if(!isok){
                    event.returnValue = false;
                }
            }
        </script>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#age").change(function(){
                    $.get("getPackByAge.php?age=1", function(data){
                        var obj = jQuery.parseJSON(data);
                        $('#packselect').children().remove().end();
                        $("#packselect").append('<option value="-1">\u65e0</option>');
                        for(var i=0;i<obj.length;i++){
                            var option = "<option value="+obj[i].packid+">"+obj[i].packcode+"-"+obj[i].name+"</option>";
                            $("#packselect").append(option);
                        }
                    });
                });
            });
        </script>
    </head>
    <body>
        <br/>
        <form id="form1" name="form1" method="post" action="search.action.php" enctype="multipart/form-data">
            <table width="75%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr>
                    <td height="30" bgcolor="#666666">位置</td>
                    <td bgcolor="#9999FF"><input type="hidden" name="id" value="<?php echo $id;?>"></input>
                        <input name="position" type="hidden" value="<?php echo $position; ?>" />
                        <input name="position_display" type="text" disabled="disabled" size="50" value="<?php echo $position; ?>" />
                    </td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">上传图片</td>
                    <td bgcolor="#9999FF"><input type="hidden" name="action" value="info"></input><input type="file" name="imageURL" size="50"></input>只能是156*156的PNG图片</td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">点击数</td>
                    <td bgcolor="#9999FF"> &nbsp; <font color=black><?php echo $click; ?></font> &nbsp; <input name="clear" type="checkbox" />选中则清除</td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;<input name="isModify" type="hidden" value="<?php echo $isModify; ?>" /></td>
                    <td bgcolor="#9999FF"><?php if ($isModify == 1) { ?><input name="id" type="hidden" value="<?php echo $id; ?>" /><?php } ?>
                        <input type="submit" name="Submit" value="提交" onclick="onSubmitCheck()" />                    </td>
                </tr>
            </table>
        </form>
        <table width="75%" border="0" align="center" cellpadding="1" cellspacing="1">
            <tr><td>
                    <?php if ($imageURL != "") { ?>
                        <img src="<?php echo $imageURL; ?>"></img><?php }
                    ?>
                    <?php
                    $sql = "SELECT * FROM t_search_detail WHERE infoID = " . $id;
                    $data = $db->fetchData($sql);
                    for ($i = 0; $i < count($data); $i++) {
                        ?>
                        <form action="search.action.php" method="post">
                            编号<input type="text" name="code" value="<?php echo $data[$i]['code']?>"></input><input type="hidden" name="action" value="detail"/><input type="hidden" name="infoID" value="<?php echo $id; ?>"></input>&nbsp;<input type="submit" value="保存"></input>&nbsp;<input type="button" value="删除"></input><font color="black">&nbsp;名称：<?php echo $data[$i]['name']; ?>&nbsp;下载次数：<?php echo 0; ?></font>
                        </form>
                    <?php } ?>
                    <form action="search.action.php" method="post">
                        编号<input type="text" name="code"></input><input type="hidden" name="action" value="detail"/><input type="hidden" name="infoID" value="<?php echo $id; ?>"/>&nbsp;<input type="submit" value="保存"></input>
                    </form>
                </td></tr>
        </table>
    </body>
</html>
<?php

function has($type, $num) {
    if (strpos($type, $num) >= 0) {
        return true;
    }
    return false;
}

include_once 'footer.php';
//} else {
//    header("login.php");
//}
?>
